﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;

namespace YJKRevitDimensionText.OneKeyPlanDim.Utility
{
	public class RevitLinkInstanceUtil
	{
		public static RevitLinkInstance GetElementLinkInstance(Autodesk.Revit.DB.Document doc, Element elem)
		{
			foreach (RevitLinkInstance revitLinkInstance in RevitLinkInstanceUtil.GetDocAllLinkInstance(doc))
			{
				if (revitLinkInstance.GetLinkDocument().PathName == elem.Document.PathName)
				{
					return revitLinkInstance;
				}
			}
			return null;
		}

		private static List<RevitLinkInstance> GetDocAllLinkInstance(Autodesk.Revit.DB.Document doc)
		{
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			filteredElementCollector.OfClass(typeof(RevitLinkInstance));
			return filteredElementCollector.Cast<RevitLinkInstance>().ToList<RevitLinkInstance>();
		}
	}
}
